/**
 * Created with JetBrains WebStorm.
 * Date: 18/01/02
 * Time: 下午2:51
 * Desc: 下载模块.
 */
import recruitTpl from './download.html';
import _ from 'underscore';
import Util from '../../common-component/util/util.js';
import Table from '../../common-component/table/table.js';
import API from '../../api/Api.js';
import Dialog from '../../common-component/dialog/dialog.js'
import commonModal from '../service-common/service-common.js';
import Pagination from '../../common-component/pagination/pagination.js';
import ChoiceDialog from '../../common-component/choice-dialog/choice-dialog.js';

import "./download.scss";

export default function DotInformation() {

    $("#app-container").html( recruitTpl({name: '下载模块'}) );
    var tHeader = [
        {CHECKBOX:true,name:'employeeId'},
        {title:'序号',INDEX:true}
        , {title: '标题', width: '120px', name: 'title', handler: function(str){
            return str;
        }}
        , {title: '前台显示', name:  'PV', handler: function(str){
            return str;
        }}
        , {title: '推荐', name:  'updateTime', handler: function(str){
            return str;
        }}
        , {title: '置顶', name:  'status', handler: function(str){
            return str;
        }}
        , {title: '更新时间', name:  'updateTime',  handler: function(str){
            return str;
        }}
        ,{title: '操作', width: '100px', hasFunc: true
            , funcList: [{name:'编辑', op: 'update', cls: 'news-update'}
            ,{name: '删除', op: 'subReview', cls: 'news-del'}
            ]}
    ];
    var data = [{
        title:'嗨皮',
        PV: '23',
        updateTime: '2017-11-22',
        status: '下架',
        index: '0',
    },{
        title:'嗨皮1',
        PV: '231',
        updateTime: '2017-11-22',
        status: '置顶',
        index: '1',
    },{
        title:'嗨皮2',
        PV: '232',
        updateTime: '2017-11-22',
        status: '推荐',
        index: '2',
    },{
        title:'嗨皮3',
        PV: '233',
        updateTime: '2017-11-22',
        status: '推荐',
        index: '3',
    },{
        title:'嗨皮4',
        PV: '234',
        updateTime: '2017-11-22',
        status: '下架',
        index: '4',
    },];

    Table($(".news-table"),'news-table',{
        tHeader: tHeader,
        data: data
    });
    const handlers = {
        checkedList: null,
        isAjax: false,
        querySearch: null,
        params: {
            pageNO: 1,
            pageSize: 10
        },
        init: function(evt) {
            const _this = this;
            this.queryForm().bindEvent();
            /*   this.querySearch = Pagination('#pagination', {
             pageSize: 10,
             url: API.queryEmployee,
             data: _this.params,
             type: 'get',
             changeParam: function(setParam, pageNO, pageSize) {
             _this.params.pageNO = pageNO;
             _this.params.pageSize = pageSize;
             setParam(_this.params);
             },
             success: function(json) {
             _this.checkedList = Table($(".news-table"), 'news-table', {
             tHeader: tHeader,
             data: json.list,
             opFunction: (obj) => {
             _this.FormButton(obj);
             }
             },() => {
             $(".news-table").colResizable({
             minWidth: 100,
             selfResize: true
             });
             });
             },
             error: function() {

             },
             complete: function() {

             }
             })*/
        },
        /*
         * 表单按钮操作
         * */
        FormButton: function (e) {
            console.log(e)
            switch(e.op) {
                case 'delete'://删除
                    window.location.href = '#/dot-personnel-detail?id=' + e.obj.employeeId
                    break;
                case 'update'://编辑
                    window.location.href = '#/dot-personnel-update?id=' + e.obj.employeeId
                    break;
            }
        },
        /**
         * 绑定事件
         */
        bindEvent: function() {
            const _this = this;
            $("body").on('click', '.js-handle', function(e) {
                const $this = $(this), handle = $this.data('handle');
                _this[handle] && _this[handle]($this, e);
            })
                .on('click', '.main-data', function() {
                    const $this = $(this), idx = $this.index();
                    if(_this.isAjax) {
                        return;
                    }
                    $this.addClass('active').siblings().removeClass('active');
                });
            return this;
        },
        /**
         * 表单
         */
        queryForm: function() {
            var v = $('#query_form').easyform(),_this = this;
            v.success = function (ef){//验证成功
                _this.params = $(ef.form).serializeObject(_this.params);
                _this.params.pageNO = 1;
                _this.querySearch(_this.params);
            };
            return this;
        },
        /**
         * 清除
         */
        clearForm: function() {
            let queryForm = $('#query_form'), _this = this;// 序列化表单内容
            queryForm[0].reset();
            this.params = {pageNO:1,pageSize:10};
            this.querySearch(this.params);
        },
        /**
         * 处理数据
         */
        processingData: function(data=[]) {
            data.map((item)=>{
                console.log(item)
            })
        },
        /**
         * 获取数据
         * @param 获取后的回调
         */
        getItems: function(cawllback) {
            this.ajaxHandle();
        },
        /**
         * ajax统一处理
         */
        ajaxHandle: function() {

        },
        /**
         * 统一提示语
         * @param msg 提示消息 string
         */
        tips: function(msg) {
            Util.alertMessage(msg);
        },
        /**
         * 获取选中数据
         */
        getTableCheckedData: function(){
            if(!this.checkedList) {
                return;
            }
            return this.checkedList();
        },
        /**
         * 导出
         */
        export: function(){
            // console.log(this.params)
            window.open(Util.exportParamFormat(API.exportEmployee,[]));
        },
        /*
         * 发布新闻
         * */
        addNews: function () {
            window.location.href = '#/download-add'
        }
    }

    handlers.init();

    var v = $('#query_form').easyform();
    v.success = function (ef){//验证成功
        handlers.params = $(ef.form).serializeObject(handlers.params);
        handlers.params.pageNO = 1;
        handlers.querySearch(handlers.params);
    }
    $('.resetBtn').on('click',function(){
        $('input[name=addressCode],input[name=companyCode]').val('');
        window.setTimeout(function(){
            handlers.params = {pageNO:1,pageSize:10};
            handlers.querySearch(handlers.params);
        },500);
    });


}